import { request } from "@/utils/http";
import {
  HospitalSetItem,
  ReqAddHospitalSetParams,
  ReqGetHospitalSetParams,
  ReqGetHospitalSetResponse,
  ReqUpdateHospitalSetParams,
} from "./types";

/**
 * 请求获取医院设置的列表
 */
export function reqGetHospitalSet(options: ReqGetHospitalSetParams) {
  //解构赋值
  let { page, limit, hoscode, hosname } = options;
  //返回请求之后的结果
  return request.get<any, ReqGetHospitalSetResponse>(
    `/admin/hosp/hospitalSet/${page}/${limit}`,
    {
      params: {
        //如果 hosname 和 hoscode 为 undefined, 则最终的 url 中不会出现查询字符串参数
        hosname: hosname,
        hoscode: hoscode,
      },
    }
  );
}

/**
 * 请求新增医院设置
 */
export function reqAddHospitalSet(data: ReqAddHospitalSetParams) {
  return request.post<any, null>("/admin/hosp/hospitalSet/save", data);
}

/**
 * 根据 id 获取医院设置的信息
 */
export function reqGetHospitalSetById(id: React.Key){
  return request.get<any, HospitalSetItem>(`/admin/hosp/hospitalSet/get/${id}`);
}

/**
 * 更新医院的设置信息
 */
export function reqUpdateHospitalSet(data: ReqUpdateHospitalSetParams){
  return request.put<any, null>('/admin/hosp/hospitalSet/update', data);
}

/**
 * 删除医院设置的信息
 */
export function reqRemoveHospital(id: React.Key){
  return request.delete<any, null>(`/admin/hosp/hospitalSet/remove/${id}`);
}

/**
 * 批量删除医院的设置信息
 */
export function reqBatchRemoveHospitalSet(data: string[]){
  return request.delete<any, null>('/admin/hosp/hospitalSet/batchRemove', {
    data
  });
}
